package com.insurance.modules.claim.controller;

import com.insurance.common.common.ResponseData;
import com.insurance.common.utils.R;
import com.insurance.modules.claim.service.TreatmentInfoService;
import com.insurance.modules.claim.vo.request.TreatmentInfoSaveReq;
import com.insurance.modules.claim.vo.response.TreatmentInfoRsp;
import com.insurance.modules.sys.controller.AbstractController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;


/**
 * 诊疗信息表
 *
 * @author weiruifeng
 * @email
 * @date 2021-09-24 17:42:47
 */
@RestController
@RequestMapping("claim/treatmentinfo")
@Api(tags = "诊疗信息")
public class TreatmentInfoController extends AbstractController {
    @Autowired
    private TreatmentInfoService treatmentInfoService;

    /**
     * 根据案件理赔表id查询诊疗信息
     */
    @PostMapping("/info")
    //@RequiresPermissions("claim:treatmentinfo:info")
    @ApiOperation(value = "根据案件理赔表id查询诊疗信息", notes = "根据案件理赔表id查询诊疗信息")
    public ResponseData<TreatmentInfoRsp> info(@RequestParam(value = "csId") String csId) {
        return ResponseData.success(treatmentInfoService.getByCsId(csId));
    }

    /**
     * 保存诊疗信息
     */
    @PostMapping("/save")
    //@RequiresPermissions("claim:treatmentinfo:save")
    @ApiOperation(value = "保存诊疗信息", notes = "保存诊疗信息")
    public R save(@RequestBody TreatmentInfoSaveReq req) {
        Date date = new Date();
        if(StringUtils.isBlank(req.getId())){
            req.setCreateBy(getUserId());
            req.setCreateTime(date);
        }
        req.setUpdateBy(getUserId());
        req.setUpdateTime(date);
        treatmentInfoService.saveTreatmentAndFile(req);
        return R.ok();
    }

}
